package com.socks.library.klog;




import com.socks.library.KLog;
import com.socks.library.KLogUtil;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;


/**
 * Created by zhaokaiqiang on 15/11/18.
 */
public class XmlLog {

    public static void printXml(String tag, String xml, String headString) {

        if (xml != null) {
//            xml = XmlLog.formatXML(xml);
            xml = headString + "\n" + xml;
        } else {
            xml = headString + KLog.NULL_TIPS;
        }

        KLogUtil.printLine(tag, true);
        String[] lines = xml.split(KLog.LINE_SEPARATOR);
        HiLogLabel label  = new HiLogLabel(HiLog.LOG_APP, 0x00201, tag);
        for (String line : lines) {
            if (!KLogUtil.isEmpty(line)) {
                HiLog.info(label,"%{public}s","║ " + line);
            }
        }
        KLogUtil.printLine(tag, false);
    }

//    private static String formatXML(String inputXML) {
//        try {
//            Source xmlInput = new StreamSource(new StringReader(inputXML));
//            StreamResult xmlOutput = new StreamResult(new StringWriter());
//            Transformer transformer = TransformerFactory.newInstance().newTransformer();
//            transformer.setOutputProperty(OutputKeys.INDENT, "yes");
//            transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
//            transformer.transform(xmlInput, xmlOutput);
//            return xmlOutput.getWriter().toString().replaceFirst(">", ">\n");
//        } catch (Exception e) {
//            e.printStackTrace();
//            return inputXML;
//        }
//    }

}
